package com.liandu.common.interceptor;

import com.liandu.common.Common;
import com.liandu.common.exception.LDException;
import com.liandu.entity.Account;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//登录拦截器
public class SessionInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Account account = (Account) session.getAttribute(Common.ACCOUNT);
        if (account == null) {
            throw LDException.of(Common.LOGIN_LOSS);
        } else {
            return true;
        }
    }
}
